#!/usr/bin/env python
# -*- coding: utf-8 -*-

class ringb(object):
    def __init__(self, count=16):
        self._count = count
        self._history = [0] * count
        self._writei = 0

    def rb_get_idx(self, idx):
        assert(idx<self._count)
        if self._writei >= idx:
            return self._writei - idx
        else:
            return self._writei+self._count-idx

    def rb_get(self):
        return self._history[self._writei]

    def rb_geto(self, offset=0):
        return self._history[self.rb_get_idx(offset)]

    def rb_pushd(self, v):
        if self.rb_get() != v:
            self.rb_push(v)

    def rb_push(self, v):
        self._writei += 1
        if self._writei == self._count: self._writei = 0
        self._history[self._writei] = v

class id_seq(ringb):
    def __init__(self, startd=0):
        self.cnts = [0]*10
        self.startd = startd
        self.rb = ringb()
        self.d = 0

    def reset(self):
        self.rb.reset()

    def push(self, depth=0):
        self.d = depth
        if depth > self.rb.rb_get():
            self.cnts[depth] = 0
        self.rb.rb_pushd(depth)
        self.cnts[depth] += 1
        return self.get()

    def get(self):
        ret = ['%d'%e for e in self.cnts[self.startd:self.d+1]]
        return '.'.join(ret)
